package com.zheng.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zheng.common.Result;
import com.zheng.entity.Exhibit;
import com.zheng.entity.Showroom;
import com.zheng.service.ExhibitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/exhibit")
public class ExhibitController {

    @Autowired
    private ExhibitService exhibitService;


    @PostMapping
    public Result<?> save(@RequestBody Exhibit exhibit){
        exhibitService.save(exhibit);
        return Result.success();
    }

    @PutMapping
    public Result<?> updateExhibit(@RequestBody Exhibit exhibit){
        exhibitService.updateById(exhibit);
        return Result.success();
    }
    @GetMapping
    //pageNum 第几页，pageSize 每页个数
    public Result<?> selectAll(@RequestParam Integer pageNum,@RequestParam Integer pageSize,@RequestParam String search,@RequestParam String option){
        System.out.println(111);
        Page<Exhibit> page = new Page<>(pageNum,pageSize);
        QueryWrapper<Exhibit> wrapper =new QueryWrapper();
        if(StrUtil.isNotBlank(search)) {
            wrapper.like(option, search);
        }
        Page<Exhibit> exhibitPage = exhibitService.page(page,wrapper);
        return  Result.success(exhibitPage);
    }

    @DeleteMapping("/{id}")
    public Result<?> deleteExhibit(@PathVariable Integer id){

        exhibitService.removeById(id);
        return Result.success();
    }

    @GetMapping("/getShowroomId")
    public Result<?> getShowroomId(@RequestParam Integer id){

        List<String> imglist = exhibitService.imgList(id);
        return Result.success(imglist);
    }

}
